{extend name="public/base"}

{block name="css"}
{/block}

{block name="main"}
<div class="layui-card">
    <blockquote class="layui-elem-quote layui-quote-nm">{empty name="data"}添加{else /}编辑{/empty}权限</blockquote>
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" placeholder="请输入"
                       autocomplete="off"
                       class="layui-input" value="{$data.name|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">导航名称</label>
            <div class="layui-input-block">
                <input type="text" name="nav_name" lay-verify="required" placeholder="请输入"
                       autocomplete="off"
                       class="layui-input" value="{$data.nav_name|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">控制器</label>
            <div class="layui-input-block">
                <input type="text" name="controller" placeholder="请输入"
                       autocomplete="off"
                       class="layui-input" value="{$data.controller|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">方法</label>
            <div class="layui-input-block">
                <input type="text" name="action" placeholder="请输入"
                       autocomplete="off"
                       class="layui-input" value="{$data.action|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="order" lay-verify="required" placeholder="请输入"
                       autocomplete="off"
                       class="layui-input" value="{$data.order|default=''}">
            </div>
        </div>

        <div class="layui-form-item" style="color: #000;">
            <label class="layui-form-label" style="z-index: 1; ">类型</label>
            <div class="layui-input-block">
                <select name="type"  style="">
                    <option value="">请选择</option>
                    <option value="1" {eq name="data.type|default=''" value="1"} selected {/eq}>网页</option>
                    <option value="3" {eq name="data.type|default=''" value="3"} selected {/eq}>模型</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" {eq name="data.status|default='1'" value="1" } checked="" {/eq} lay-skin="switch"
                lay-filter="component-form-switchTest" lay-text="开启|关闭">
            </div>
            <input name="status" type="hidden" value="{$data.status|default='1'}"/>
        </div>

        <div class="layui-form-item" style="color: #000;">
            <label class="layui-form-label" style="z-index: 1; ">上级权限</label>
            <div class="layui-input-inline">
                <select name="parent_id"  style="">
                    <option value="0">请选择</option>
                    {volist name="auths" id="vo"}
                        <option value="{$vo.id}" {eq name="data.parent_id|default=0" value="$vo.id"} selected {/eq}>{php}echo str_repeat("&nbsp;", $vo['level'] * 6);{/php}{$vo.name}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <!--<div class="layui-footer">-->
                <input type="hidden" name="id" value="{$data.id|default=0}">
                <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">提 交</button>
                <!--</div>-->
            </div>
        </div>
    </form>
</div>
{/block}

{block name="js"}
<script>
    layui.config({
        base: '/layui_admin/src/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        let $ = layui.$
            , form = layui.form, admin = layui.admin;

        /* 监听指定开关 */
        form.on('switch(component-form-switchTest)', function (data) {
            let input_status = $('input[name="status"]');
            console.log(this.checked);
            this.checked ? input_status.val(1) : input_status.val(2);
        });

        /* 监听提交 */
        form.on('submit(component-form-demo1)', function (data) {
            layer.load();
            //请求登入接口
            admin.req({
                url: "{:url('save_auth')}" //实际使用请改成服务端真实接口
                ,type : 'post'
                ,data: data.field
                ,done: function(res){
                    //登入成功的提示与跳转
                    layer.msg('保存成功！', {
                        offset: '15px'
                        ,icon: 1
                        ,time: 1000
                    }, function(){
                        parent.location.reload(); //刷新页面
                    });
                }
            });
            return false;
        });
    });
</script>
{/block}